<%@page contentType="text/html" import="java.util.Collection, Bean.*"%>
<%@page pageEncoding="UTF-8"%>
<%@ taglib uri="/WEB-INF/taglib139.tld" prefix="pg" %>
<%--
The taglib directive below imports the JSTL library. If you uncomment it,
you must also add the JSTL library to the project. The Add Library... action
on Libraries node in Projects view can be used to add the JSTL 1.1 library.
--%>

<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> 

<%
if(session.getAttribute("un")==null){
    response.sendRedirect("indexAdmin.jsp?page=Admin&url=Login");
    out.println("You must be login..!");
}else{%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<script language="javascript" type="text/javascript" src="../script/validate.js"></script>
<script language="javascript">
       function kiemtra(){
            var id = document.form1.txtsemid;
            var name = document.form1.txtsemname;
            if( laChuoiRong(id.value))
            {
                alert('Semester ID is not blank!');
                id.focus();
                return false;
            }
            if( laChuoiRong(name.value))
            {
                alert('Semester name is not blank!');
                name.focus();
                return false;
            }
            
       }
</script>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <%
        String r="";String n="";String g="";
        if(session.getAttribute("semid")!=null){
            r=session.getAttribute("semid").toString();
            
            g=session.getAttribute("semname").toString();
        }
        %>
        <%
        CurriculumBean ojb1=new CurriculumBean();
        Collection kq1=ojb1.getListCurriculum();
        request.setAttribute("st1", kq1);
        %>
        <form method="POST" action="../ControllSemester" name="form1" onsubmit="return kiemtra()">
            <h3 align="center">Semester management</h3>
            <table>
                
               
                <tr>
                    <td>SemID</td>
                    <td><input type="text" name="txtsemid" value="<%=r%>" /><input type="hidden" name="tempsemname" value="<%=r%>" /></td>
                </tr>
                <tr>
                    <td>CurID</td>
                    <td><select name="ddlcurid">
                            <c:forEach items="${st1}" var="s1">
                                <option>${s1.curid}</option>    
                            </c:forEach>
                            
                    </select></td>
                </tr>
                <tr>
                    <td>SemName</td>
                    <td><input type="text" name="txtsemname" value="<%=g%>" /></td>
                </tr>
                <tr>
                    <td></td>
                    <td colspan="2">
                        <input type="submit" value="Insert" name="bt" />
                        <input type="submit" value="Update" name="bt" />
                        <input type="button" value="Reset" name="bt"  onclick="clear_fields()" />
                    </td>
                </tr>
            </table>
            <%
            SemesterBean ojb=new SemesterBean();
            Collection kq=ojb.getListSemester();
            request.setAttribute("st", kq);
            %>
            <table border="1">
                <tr>
                    <th>SemID</th>
                    <th>CurID</th>
                    <th>Semname</th>
                    <th colspan="2">Action</th>
                </tr>
                <pg:paging pageSize="10" url="indexAdmin.jsp?page=Admin&url=Semester"> 
                    <c:forEach items="${st}" var="s">
                        <pg:item> 
                            <tr>
                                <td><c:out value="${s.semid}" /></td>
                                <td>${s.curid}</td>
                                <td>${s.semname}</td>
                                
                                <c:url var="delete" value="../ControllSemester">
                                    <c:param name="bt" value="Delete" />
                                    <c:param name="semid" value="${s.semid}" />
                                    <c:param name="p" value="${param.pageNum}"/>
                                </c:url>
                                <c:url var="edit" value="../ControllSemester">
                                    <c:param name="bt" value="Edit" />
                                    <c:param name="semid" value="${s.semid}" />
                                    <c:param name="curid" value="${s.curid}" />
                                    <c:param name="semname" value="${s.semname}" />
                                    <c:param name="p" value="${param.pageNum}"/>
                                </c:url>
                                <% if(session.getAttribute("permission")!=null){
                                    if(session.getAttribute("permission").equals("Academic")){%>
                                    <td><a href="${edit}">Edit</a></td>
                                <%    
                                    }
                                %>
                                <% 
                                    if(session.getAttribute("permission").equals("Admin")){%>
                                    <td><a href="${edit}">Edit</a></td>
                                    <td><a href="${delete}" onclick="return confirm('Do you really want to delete these records ?')">Delete</a></td>
                                <%    
                                    }
                                %>
                                <%}%>
                            </tr>
                        </pg:item>
                    </c:forEach>
                    <pg:index>
                        <pg:page><%=thisPage%></pg:page>
                        <pg:firstPage>[First]</pg:firstPage>
                        <pg:lastPage>[Last]</pg:lastPage> 
                    </pg:index> 
                </pg:paging> 
            </table>
        </form>
    </body>
</html>
<%}%>